﻿using System;
using System.Collections.Generic;
using System.Reflection;
using BotonJXC.DAO;
using BotonJXC.Entity;
using NHibernate.Criterion;

namespace BotonJXC.BLL
{
    public abstract class BaseBLL<D, T, PK>
        where T : BaseEntity
        where D : NHibernateDao<T, PK>
    {
        D _dao = null;
        protected D Dao
        {
            get
            {
                if (_dao == null)
                    _dao = (D)Activator.CreateInstance(typeof(D));
                return _dao;
            }
        }

        public T Get(PK id)
        {
            return Dao.Get(id);
        }
        public void Save(T entity)
        {
            Dao.Save(entity);
        }
        public void Update(T entity)
        {
            Dao.Update(entity);
        }
        public void Delete(T entity)
        {
            Dao.Delete(entity);
        }
        public void Delete(PK id)
        {
            Dao.Delete(Get(id));
        }
        public virtual IList<T> FindAll()
        {
            return Dao.Find(new ICriterion[]{});
        }
    }
}